public class demo6 {
    public static void main(String[] args) {
        Object lock=new Object();

        Thread t1=new Thread(()->{
            synchronized (lock){
                int sum=0;
                for (int i = 1; i <=10; i++) {
                    sum+=i;
                }
                lock.notify();
            }

        });

        Thread t2=new Thread(()->{
            synchronized (lock){
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                int sum=0;
                for (int i = 1; i <=10; i++) {
                    sum+=i;
                }
                lock.notify();
            }

        });

        Thread t3=new Thread(()->{
            synchronized (lock){
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                int sum=0;
                for (int i = 21; i <=30; i++) {
                    sum+=i;
                }
                lock.notify();
            }
        });


        t1.start();
        t2.start();
        t3.start();
    }
}
